# Copyright (c) 2010 The Foundry Visionmongers Ltd.  All Rights Reserved. #

import maya.cmds as cmds
import sys
import os.path
import my.ScenegraphXML.maya2scenegraphXML as maya2scenegraphXML

reload(maya2scenegraphXML)

YellowPaintParts = [u'Robot_part_01:Box332', u'Robot_part_02:Box299', u'Robot_part_02:Box296', u'Robot_part_02:Box298',
                    u'Robot_part_02:Box294', u'Robot_part_01:Box318', u'Robot_part_05:Box333', u'Robot_part_05:Box334',
                    u'Robot_part_05:Box337', u'Robot_part_05:Box338', u'Robot_part_04:Box293', u'Robot_part_04:Box290',
                    u'Robot_part_04:Box289', u'Robot_part_04:Box09', u'Robot_part_04:Plane52', u'Robot_part_05:Plane54',
                    u'Robot_part_04:Plane51', u'Robot_part_04:Plane02', u'Robot_part_05:Box336',
                    u'Robot_part_05:Plane56', u'Robot_part_05:Box335', u'Robot_part_05:Plane55',
                    u'Robot_part_04:Box291', u'Robot_part_04:Box292', u'Robot_part_03:Cylinder1765',
                    u'Robot_part_05:Plane57', u'Robot_part_04:Plane53']

DarkMetalParts = [u'Robot_part_01:ChamferCyl214', u'Robot_part_01:ChamferCyl203', u'Robot_part_01:Box304',
                  u'Robot_part_01:ChamferCyl213', u'Robot_part_01:Box331', u'Robot_part_05:Cylinder3875',
                  u'Robot_part_05:Cylinder3908', u'Robot_part_05:Cylinder3895', u'Robot_part_04:Cylinder3784',
                  u'Robot_part_04:Cylinder2342', u'Robot_part_05:Cylinder3888', u'Robot_part_04:Cylinder3777',
                  u'Robot_part_04:Cylinder2389']

BrightBronzeParts = [u'Robot_part_01:Capsule59', u'Robot_part_02:Cylinder3068', u'Robot_part_02:Cylinder3852',
                     u'Robot_part_05:Capsule60', u'Robot_part_04:Capsule28', u'Robot_part_05:Object170',
                     u'Robot_part_04:Object114', u'Robot_part_04:Cylinder2246', u'Robot_part_05:Cylinder3904',
                     u'Robot_part_04:Object02', u'Robot_part_05:Object176', u'Robot_part_02:Box08',
                     u'Robot_part_03:Line91', u'Robot_part_05:Circle716', u'Robot_part_04:Carcase_metal01',
                     u'Robot_part_05:Carcase_metal04', u'Robot_part_04:Sphere03', u'Robot_part_05:Sphere1802',
                     u'Robot_part_04:Circle500', u'Robot_part_02:Cylinder3166', u'Robot_part_01:Capsule55',
                     u'Robot_part_04:Sphere1135', u'Robot_part_05:Sphere1799', u'Robot_part_01:Box300',
                     u'Robot_part_01:Box329', u'Robot_part_02:Arc16', u'Robot_part_01:Cylinder3694',
                     u'Robot_part_01:Cylinder3856', u'Robot_part_02:Sphere1780', u'Robot_part_02:Sphere1332',
                     u'Robot_part_04:Sphere1163', u'Robot_part_05:Sphere1806']

DarkBronzeParts = [u'Robot_part_01:Box330', u'Robot_part_01:Tube92', u'Robot_part_01:Line767',
                   u'Robot_part_01:Sphere1782', u'Robot_part_01:Cylinder3857', u'Robot_part_01:Cylinder3858',
                   u'Robot_part_01:Cylinder3859', u'Robot_part_01:ChamferCyl215', u'Robot_part_01:Object168',
                   u'Robot_part_01:Tube86', u'Robot_part_01:Line698', u'Robot_part_01:Box312',
                   u'Robot_part_01:Sphere1781', u'Robot_part_01:Cylinder3565', u'Robot_part_01:Cylinder3526',
                   u'Robot_part_01:Object09', u'Robot_part_01:Cylinder3539', u'Robot_part_03:Box01',
                   u'Robot_part_03:Box02', u'Robot_part_03:ChamferCyl05', u'Robot_part_03:Black_metal',
                   u'Robot_part_02:Sphere1331', u'Robot_part_02:Cylinder3700', u'Robot_part_02:Cylinder3703',
                   u'Robot_part_02:Cylinder3688', u'Robot_part_02:Object03', u'Robot_part_02:Sphere1779',
                   u'Robot_part_02:Cylinder3853', u'Robot_part_02:Cylinder3854', u'Robot_part_02:Cylinder3855',
                   u'Robot_part_02:Object169', u'Robot_part_02:Box243', u'Robot_part_02:Line659',
                   u'Robot_part_02:Capsule36', u'Robot_part_02:Carcase_metal05', u'Robot_part_02:Sphere1814',
                   u'Robot_part_02:Sphere1813', u'Robot_part_02:Line773', u'Robot_part_02:ChamferCyl157',
                   u'Robot_part_04:Sphere01', u'Robot_part_04:Cylinder2561', u'Robot_part_04:Sphere1250',
                   u'Robot_part_04:Tube43', u'Robot_part_04:Tube91', u'Robot_part_05:Sphere1778',
                   u'Robot_part_04:Tube47', u'Robot_part_04:Cylinder2181', u'Robot_part_04:Rectangle57',
                   u'Robot_part_04:Cylinder1891', u'Robot_part_04:Detail_37', u'Robot_part_04:Detail_41',
                   u'Robot_part_04:Sphere02', u'Robot_part_04:Detail_53', u'Robot_part_04:Sphere1154',
                   u'Robot_part_04:Line760', u'Robot_part_04:Line577', u'Robot_part_04:Cylinder1875',
                   u'Robot_part_04:Object01', u'Robot_part_04:Object08', u'Robot_part_04:Line635',
                   u'Robot_part_04:Sphere1783', u'Robot_part_05:Tube93', u'Robot_part_05:Line768',
                   u'Robot_part_05:Cylinder3860', u'Robot_part_05:Rectangle58', u'Robot_part_05:Cylinder3865',
                   u'Robot_part_05:Detail_55', u'Robot_part_05:Detail_56', u'Robot_part_05:Sphere1797',
                   u'Robot_part_05:Sphere1798', u'Robot_part_05:Line769', u'Robot_part_05:Line770',
                   u'Robot_part_05:Cylinder3866', u'Robot_part_05:Object172', u'Robot_part_05:Object173',
                   u'Robot_part_05:Cylinder3867', u'Robot_part_05:Circle711', u'Robot_part_05:Sphere1801',
                   u'Robot_part_05:Detail_59', u'Robot_part_04:Sphere1153', u'Robot_part_04:Cylinder2183',
                   u'Robot_part_04:Cylinder2188', u'Robot_part_04:Cylinder2189', u'Robot_part_04:Circle489',
                   u'Robot_part_04:Cylinder2194', u'Robot_part_04:Cylinder1949', u'Robot_part_04:Circle456',
                   u'Robot_part_04:Object04', u'Robot_part_04:Cylinder2123', u'Robot_part_04:Circle455',
                   u'Robot_part_04:Circle457', u'Robot_part_04:Cylinder1966', u'Robot_part_04:Tube29',
                   u'Robot_part_04:Object05', u'Robot_part_04:Circle494', u'Robot_part_04:Sphere1157',
                   u'Robot_part_04:Object07', u'Robot_part_05:Sphere1796', u'Robot_part_05:Cylinder3861',
                   u'Robot_part_05:Cylinder3862', u'Robot_part_05:Cylinder3863', u'Robot_part_05:Circle710',
                   u'Robot_part_05:Cylinder3864', u'Robot_part_05:Object174', u'Robot_part_05:Cylinder3868',
                   u'Robot_part_05:Circle712', u'Robot_part_05:Circle713', u'Robot_part_05:Cylinder3869',
                   u'Robot_part_05:Circle714', u'Robot_part_05:Tube95', u'Robot_part_05:Object171',
                   u'Robot_part_05:Sphere1800', u'Robot_part_05:Object177', u'Robot_part_04:Cylinder2230',
                   u'Robot_part_04:Line09', u'Robot_part_04:Object06', u'Robot_part_04:Detail_51',
                   u'Robot_part_04:Capsule29', u'Robot_part_04:Cylinder2216', u'Robot_part_04:Cylinder2247',
                   u'Robot_part_04:Sphere1164', u'Robot_part_04:Cylinder2212', u'Robot_part_04:Cylinder2307',
                   u'Robot_part_04:Sphere1176', u'Robot_part_04:Cylinder2304', u'Robot_part_04:Sphere1173',
                   u'Robot_part_04:Line590', u'Robot_part_04:Sphere1169', u'Robot_part_04:Sphere1795',
                   u'Robot_part_05:Line771', u'Robot_part_05:Object175', u'Robot_part_05:Capsule61',
                   u'Robot_part_05:Cylinder3900', u'Robot_part_05:Cylinder3901', u'Robot_part_05:Sphere1807',
                   u'Robot_part_05:Cylinder3902', u'Robot_part_05:Cylinder3903', u'Robot_part_05:Sphere1808',
                   u'Robot_part_05:Cylinder3905', u'Robot_part_05:Sphere1809', u'Robot_part_05:Line772',
                   u'Robot_part_05:Sphere1811', u'Robot_part_05:Sphere1812', u'Robot_part_05:Cylinder3870',
                   u'Robot_part_04:Circle479', u'Robot_part_04:Tube36', u'Robot_part_04:Carcase_metal02',
                   u'Robot_part_04:Rust_aluminium02', u'Robot_part_04:Cylinder2406', u'Robot_part_04:Circle522',
                   u'Robot_part_04:Cylinder2392', u'Robot_part_04:Circle519', u'Robot_part_04:Cylinder2384',
                   u'Robot_part_04:Cylinder2387', u'Robot_part_04:Cylinder2385', u'Robot_part_04:Cylinder2390',
                   u'Robot_part_04:Cylinder2391', u'Robot_part_04:Cylinder2343', u'Robot_part_04:Circle517',
                   u'Robot_part_04:Cylinder2369', u'Robot_part_04:Cylinder2368', u'Robot_part_04:Cylinder2340',
                   u'Robot_part_04:Cylinder2339', u'Robot_part_04:Cylinder2338', u'Robot_part_04:Cylinder3774',
                   u'Robot_part_04:Circle708', u'Robot_part_04:Cylinder3775', u'Robot_part_04:Cylinder3776',
                   u'Robot_part_04:Cylinder3778', u'Robot_part_04:Cylinder3779', u'Robot_part_04:Cylinder3780',
                   u'Robot_part_04:Cylinder3781', u'Robot_part_04:Circle709', u'Robot_part_04:Cylinder3782',
                   u'Robot_part_04:Cylinder3783', u'Robot_part_04:Cylinder3785', u'Robot_part_04:Cylinder3786',
                   u'Robot_part_04:Cylinder3787', u'Robot_part_04:Sphere1787', u'Robot_part_04:Detail_54',
                   u'Robot_part_04:Sphere1784', u'Robot_part_04:Cylinder2013', u'Robot_part_04:Sphere1785',
                   u'Robot_part_04:Cylinder2213', u'Robot_part_04:Cylinder2009', u'Robot_part_04:Sphere1167',
                   u'Robot_part_05:Circle715', u'Robot_part_05:Tube94', u'Robot_part_05:Carcase_metal03',
                   u'Robot_part_05:Rust_aluminium03', u'Robot_part_05:Cylinder3871', u'Robot_part_05:Circle717',
                   u'Robot_part_05:Cylinder3872', u'Robot_part_05:Circle718', u'Robot_part_05:Cylinder3873',
                   u'Robot_part_05:Cylinder3874', u'Robot_part_05:Cylinder3876', u'Robot_part_05:Cylinder3877',
                   u'Robot_part_05:Cylinder3878', u'Robot_part_05:Cylinder3879', u'Robot_part_05:Circle719',
                   u'Robot_part_05:Cylinder3880', u'Robot_part_05:Cylinder3881', u'Robot_part_05:Cylinder3882',
                   u'Robot_part_05:Cylinder3883', u'Robot_part_05:Cylinder3884', u'Robot_part_05:Cylinder3885',
                   u'Robot_part_05:Circle720', u'Robot_part_05:Cylinder3886', u'Robot_part_05:Cylinder3887',
                   u'Robot_part_05:Cylinder3889', u'Robot_part_05:Cylinder3890', u'Robot_part_05:Cylinder3891',
                   u'Robot_part_05:Cylinder3892', u'Robot_part_05:Circle721', u'Robot_part_05:Cylinder3893',
                   u'Robot_part_05:Cylinder3894', u'Robot_part_05:Cylinder3896', u'Robot_part_05:Cylinder3897',
                   u'Robot_part_05:Cylinder3898', u'Robot_part_05:Sphere1803', u'Robot_part_05:Detail_57',
                   u'Robot_part_05:Sphere1804', u'Robot_part_05:Cylinder3899', u'Robot_part_05:Detail_58',
                   u'Robot_part_05:Sphere1805', u'Robot_part_05:Cylinder3906', u'Robot_part_05:Cylinder3907',
                   u'Robot_part_05:Sphere1810']

maya2scenegraphXML.mayaAssignTagToShape(YellowPaintParts, 'MatTag', 'Paint')
maya2scenegraphXML.mayaAssignTagToShape(YellowPaintParts, 'ColMapTag', 'Yellow_paint_04_COLOR')
maya2scenegraphXML.mayaAssignTagToShape(YellowPaintParts, 'SpecMapTag', 'Yellow_paint_04_SPEC')

maya2scenegraphXML.mayaAssignTagToShape(DarkMetalParts, 'MatTag', 'Metal')
maya2scenegraphXML.mayaAssignTagToShape(DarkMetalParts, 'ColMapTag', 'Metal_paint_03_COLOR')
maya2scenegraphXML.mayaAssignTagToShape(DarkMetalParts, 'SpecMapTag', 'Metal_paint_03_SPEC')

maya2scenegraphXML.mayaAssignTagToShape(BrightBronzeParts, 'MatTag', 'Metal')
maya2scenegraphXML.mayaAssignTagToShape(BrightBronzeParts, 'ColMapTag', 'Bronze_01_COLOR')
maya2scenegraphXML.mayaAssignTagToShape(BrightBronzeParts, 'SpecMapTag', 'Bronze_01_SPEC')

maya2scenegraphXML.mayaAssignTagToShape(DarkBronzeParts, 'MatTag', 'Metal')
maya2scenegraphXML.mayaAssignTagToShape(DarkBronzeParts, 'ColMapTag', 'Bronze_02_COLOR')
maya2scenegraphXML.mayaAssignTagToShape(DarkBronzeParts, 'SpecMapTag', 'Bronze_02_SPEC')

maya2scenegraphXML.deleteSgxmlAttrs('|Robot')

maya2scenegraphXML.setProxy(['head', 'head_hi'], 'head_proxy.abc')
maya2scenegraphXML.setProxy(['shoulderR', 'shoulderR_hi'], 'shoulderR_proxy.abc')
maya2scenegraphXML.setProxy(['shoulderL', 'shoulderL_hi'], 'shoulderL_proxy.abc')
maya2scenegraphXML.setProxy(['torso', 'torso_hi'], 'torso_proxy.abc')
maya2scenegraphXML.setProxy(['hips', 'hips_hi'], 'hips_proxy.abc')
maya2scenegraphXML.setProxy(['armUpperL', 'armUpperL_hi'], 'armUpperL_proxy.abc')
maya2scenegraphXML.setProxy(['armLowerL', 'armLowerL_hi'], 'armLowerL_proxy.abc')
maya2scenegraphXML.setProxy(['armUpperR', 'armUpperR_hi'], 'armUpperR_proxy.abc')
maya2scenegraphXML.setProxy(['armLowerR', 'armLowerR_hi'], 'armLowerR_proxy.abc')
maya2scenegraphXML.setProxy(['legUpperL', 'legUpperL_hi'], 'legUpperL_proxy.abc')
maya2scenegraphXML.setProxy(['legMidL', 'legMidL_hi'], 'legMidL_proxy.abc')
maya2scenegraphXML.setProxy(['shinL', 'shinL_hi'], 'shinL_proxy.abc')
maya2scenegraphXML.setProxy(['footL', 'footL_hi'], 'footL_proxy.abc')
maya2scenegraphXML.setProxy(['legUpperR', 'legUpperR_hi'], 'legUpperR_proxy.abc')
maya2scenegraphXML.setProxy(['legMidR', 'legMidR_hi'], 'legMidR_proxy.abc')
maya2scenegraphXML.setProxy(['shinR', 'shinR_hi'], 'shinR_proxy.abc')
maya2scenegraphXML.setProxy(['footR', 'footR_hi '], 'footR_proxy.abc')

maya2scenegraphXML.setAssembly(['upperBody', 'mainBody'])

maya2scenegraphXML.setComponent(
    ['armUpperL_hi', 'armLowerL_hi', 'armUpperR_hi', 'armLowerR_hi', 'head_hi', 'shoulderR_hi', 'shoulderL_hi',
     'torso_hi', 'hips_hi', 'legUpperR_hi', 'legUpperL_hi', 'legMidR_hi', 'legMidL_hi', 'shinR_hi', 'shinL_hi',
     'footR_hi', 'footL_hi'], refType='abc')

maya2scenegraphXML.setStaticComponent(
    ['armUpperL_lo', 'armLowerL_lo', 'armUpperR_lo', 'armLowerR_lo', 'head_lo', 'shoulderR_lo', 'shoulderL_lo',
     'torso_lo', 'hips_lo', 'legUpperR_lo', 'legUpperL_lo', 'legMidR_lo', 'legMidL_lo', 'shinR_lo', 'shinL_lo',
     'footR_lo', 'footL_lo'], refType='abc')

maya2scenegraphXML.setLodGroup(
    ['armUpperL', 'armLowerL', 'armUpperR', 'armLowerR', 'head', 'shoulderR', 'shoulderL', 'torso', 'hips', 'legUpperR',
     'legUpperL', 'legMidR', 'legMidL', 'shinR', 'shinL', 'footR', 'footL'])

maya2scenegraphXML.setLodNode(
    ['armUpperL_lod_hi', 'armLowerL_lod_hi', 'armUpperR_lod_hi', 'armLowerR_lod_hi', 'head_lod_hi', 'shoulderR_lod_hi',
     'shoulderL_lod_hi', 'torso_lod_hi', 'hips_lod_hi', 'legUpperR_lod_hi', 'legUpperL_lod_hi', 'legMidR_lod_hi',
     'legMidL_lod_hi', 'shinR_lod_hi', 'shinL_lod_hi', 'footR_lod_hi', 'footL_lod_hi'], lodTag='hi', lodWeight=1.0)

maya2scenegraphXML.setLodNode(
    ['armUpperL_lod_lo', 'armLowerL_lod_lo', 'armUpperR_lod_lo', 'armLowerR_lod_lo', 'head_lod_lo', 'shoulderR_lod_lo',
     'shoulderL_lod_lo', 'torso_lod_lo', 'hips_lod_lo', 'legUpperR_lod_lo', 'legUpperL_lod_lo', 'legMidR_lod_lo',
     'legMidL_lod_lo', 'shinR_lod_lo', 'shinL_lod_lo', 'footR_lod_lo', 'footL_lod_lo'], lodTag='lo', lodWeight=0.0)

maya2scenegraphXML.setArbAttr(['Robot'], 'myFloat', 1.0, 'float')
maya2scenegraphXML.setArbAttr(['Robot'], 'myString', "foo", 'string')

exportDirectory = "/mnt/project/bao/Proj_Maya/new_project/scenes/scenegraphWrite/robot_data_abc"

# Export main geometry
maya2scenegraphXML.maya2ScenegraphXML(['|Robot'], os.path.join(exportDirectory, 'Robot.xml'),
                                      startFrame=1,
                                      endFrame=24,
                                      arbAttrs=['myFloat', 'myString'],
                                      geoFileOptions='-uv -attr ColMapTag -attr SpecMapTag -attr BumpMapTag -attr MatTag')

# Export proxies geometry
proxyGroups = cmds.ls("*_lod_lo")
for proxyGroup in proxyGroups:
    proxyFileName = proxyGroup[:-7] + "_proxy.abc"
    proxyFilePath = os.path.join(exportDirectory, proxyFileName)
    print "Exporting Proxy: %s" % proxyFilePath
    cmds.AbcExport(j="-uv -root %s -file %s" % (proxyGroup, proxyFilePath))
